package com.eight.vote.controller;


import com.eight.vote.pojo.VUser;
import com.eight.vote.service.VUserService;
import com.eight.vote.util.Result;
import com.eight.vote.vo.LoginFrom;
import com.eight.vote.vo.UpdatePasswordVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 点点星言
 * @since 2022-10-16
 */
@Slf4j
@RestController
@RequestMapping("/api/user")
public class VUserController {

    @Autowired
    VUserService userService;

    /**
     * 登录方法
     * @param loginFrom
     * @return
     */
    @PostMapping("login")
    public Result login(@RequestBody LoginFrom loginFrom){

        return userService.login(loginFrom);
    }

    /**
     * 注册
     * @param loginFrom
     * @return
     */
    @PostMapping("reg")
    public Result register(@RequestBody LoginFrom loginFrom){
        return userService.register(loginFrom);
    }

    /**
     * 修改个人信息
     * @return
     */
    @PostMapping("updateUser")
    public Result updateUser(@RequestBody VUser user){
        log.debug("获取到的数据：{}",user);
        return userService.updateUser(user);
    }


    @PostMapping("updatePassword")
    public Result updatePassword(@RequestBody UpdatePasswordVO updatePasswordVO){
        log.debug("获取到的数据{}",updatePasswordVO.toString());
        return userService.updatePassword(updatePasswordVO);

    }





}

